<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: snow_header"></head>
<body class="gray-bg">
    <div class="container-div">
		<form id="user-form">
			<div class="select-list">
				<ul>
					<li>
						文件字节最小限制：<input id="minSize" type="text" name="maxSize" style="width:160px"/>
					</li>
					<li>
						文件字节最大限制：<input id="maxSize" type="text" name="maxSize" style="width:160px"/>
					</li>
					<li>
						<a id="search" class="btn btn-primary btn-rounded btn-sm" onclick="tableSearch()"><i class="fa fa-search"></i>&nbsp;搜索</a>
					</li>
					<li>
						<div id="msg_console"></div>
					</li>
				</ul>
			</div>
		</form>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true" style="white-space:nowrap"></table>
		</div>
    </div>
	<div th:include="include :: snow_footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('module:ossconfig:edit')}]];
        var removeFlag = [[${@permission.hasPermi('module:ossconfig:remove')}]];
		var releaseFlag = [[${@permission.hasPermi('module:ossconfig:release')}]];
        var prefix = ctx + "module/osssearch";

        var columnVisible=editFlag=='hidden'?'gone':'visible'
		columnVisible=editFlag=='hidden'?false:true

		var bootstrapTable=$.snowBootstrap.init("bootstrap-table");
        $(function() {
            var options = {
                // url: prefix + "/list",
                modalName: "阿里云OSS资源搜索",
                columns: [{
		            checkbox: true
		        },
                {
                    field : 'fileName',
                    title : '文件名'
                },
                {
                    field : 'url',
                    title : '链接',
					formatter: function (value, row, index) {
						var actions = [];
						actions.push('<a class="' +  '" href="'+value+'" target="_blank" >'+value+'</a>');

						return actions.join('');
					}
                },
                {
                    field : 'fileSize',
                    title : '文件大小'
                },
				{
					field : 'fileSizeStr',
					title : '文件大小'
				},
                {
                    field : 'lastModified',
                    title : '修改时间'
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
						// actions.push('<a class="btn btn-danger btn-xs ' + releaseFlag + '" href="#" onclick="editContent(\'' + row.ossConfigId + '\')"><i class="fa fa-edit"></i>内容编辑</a>');

						return actions.join('');
		            }
		        }],
				search: false,
            };
            console.log("options=",options);
			bootstrapTable.tableInit(options);
        });


        var searchFlag=false;
		var total=0;

		function tableSearch() {

			var search = $("#search");
			if(!searchFlag){
				search.addClass("btn-danger");
				search.removeClass("btn-primary");
				searchFlag=true;
				$(search).html('<i class="fa fa-search"></i>&nbsp;停止');
			}else{
				searchFlag=false;
				search.removeClass("btn-danger");
				search.addClass("btn-primary");
				$(search).html('<i class="fa fa-search"></i>&nbsp;搜索');
				return;
			}

			var total=0
			bootstrapTable._bootStrapTable.bootstrapTable('removeAll');
			var param={};

			if(!$.common.isEmpty($("#minSize").val()))
			{
				param['minSize']= $("#minSize").val();
			}
			if(!$.common.isEmpty($("#maxSize").val()))
			{
				param['maxSize']= $("#maxSize").val();
			}

			searchOss(param);

		}

		function searchOss(param) {
			var config = {
				url:  "/module/osssearch/list",
				type: "post",
				dataType: "json",
				data: param,
				success: function(result) {
					console.log(result);
					bootstrapTable._bootStrapTable.bootstrapTable('append', result.list);
					total=total+result.total;
					$("#msg_console").text("["+total+"]查找中."+result.nextMarker);
					if(searchFlag){
						if(result.isTruncated){
							param['nextMarker']=result.nextMarker;
							searchOss(param);
						}else{
							$("#msg_console").text("查找结束");
						}
					}else{
						total=total+result.total;
						$("#msg_console").text("["+total+"]查找结束,强制停止");
					}
				}
			};
			$.ajax(config);
		}


    </script>
</body>
</html>